//
//  YDBankListCell.m
//  PeiZiWangBei
//
//  Created by 巨彦新 on 2018/1/3.
//  Copyright © 2018年 LK-IOS. All rights reserved.
//

#import "YDBankListCell.h"

@interface YDBankListCell ()
@property (nonatomic, strong) UIView *bgView;       //背景
@property (nonatomic, strong) UIImageView *bankIcon;//卡的icon
@property (nonatomic, strong) UILabel *bankNameLbl; //银行名称
@property (nonatomic, strong) UILabel *bankTypeLbl; //银行卡类型
@property (nonatomic, strong) UILabel *bankNumLbl;  //卡号
@end



@implementation YDBankListCell



+ (instancetype)cellWithTableView:(UITableView *)tableview
{
    static NSString *const BankListCell = @"BankListCell";
    
    YDBankListCell *cell = [tableview dequeueReusableCellWithIdentifier:BankListCell];
    
    if (cell == nil) {
        cell = [[YDBankListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:BankListCell];
        
    }
    return cell;
}
                                
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = NumberColor(255, 255, 255);
        [self bgView];
        [self bankIcon];
        [self bankNameLbl];
        [self bankNumLbl];
        [self bankTypeLbl];
        
    
        
    }
    return self;
}

-(void)setCardModel:(YDBankCardModel *)cardModel
{
    _cardModel = cardModel;
    [self.bankIcon sd_setImageWithURL:[NSURL URLWithString:cardModel.bankIconLink] placeholderImage:[UIImage imageNamed:@"zhanweibank"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
   
        if (image == nil) {
            self.bgView.backgroundColor = [UIColor colorWithHexString:blueyGrey];
        }else
        {
            if ([cardModel.bankName isEqualToString:@"中国民生银行"]) {//民生取色为灰色
                self.bgView.backgroundColor = NumberColor(20, 153, 76);
            }else
            {
                self.bgView.backgroundColor = [UIImage mostColor:image];
            }
            
        }
        
    }];
    self.bankNameLbl.text = cardModel.bankName;
    self.bankNumLbl.text = cardModel.fourStarFormatterBankCard;
    
    
}

-(UIView *)bgView
{
    if (_bgView == nil) {
        _bgView = [UIView new];
        [self.contentView addSubview:_bgView];
        [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
           
            make.left.equalTo(@(rate375(18)));
            make.right.equalTo(@(-rate375(18)));
            if (isPhoneX) {
                make.height.equalTo(@(rateX812(90)));
                make.top.equalTo(@(rateX812(10)));
            }else
            {
                make.height.equalTo(@(rate750(90)));
                make.top.equalTo(@(rate750(10)));
            }
        }];
        _bgView.layer.cornerRadius = 8;
        _bgView.clipsToBounds = YES;
        _bgView.backgroundColor = [UIColor colorWithHexString:blueyGrey];
    }
    return _bgView;
}

- (UIImageView *)bankIcon
{
    if (_bankIcon == nil) {
        _bankIcon = [UIImageView new];
        [self.contentView addSubview:_bankIcon];
        [_bankIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.equalTo(@(rate375(60)));
            make.centerY.equalTo(_bgView);
            make.left.equalTo(_bgView.mas_left).offset(rate375(16));
            
        }];
         _bankIcon.layer.cornerRadius = rate375(30);
        _bankIcon.clipsToBounds = YES;
        _bankIcon.backgroundColor = [UIColor whiteColor];
    }
    return _bankIcon;
}

- (UILabel *)bankNameLbl
{
    if (_bankNameLbl == nil) {
        _bankNameLbl = [UILabel new];
        [self.contentView addSubview:_bankNameLbl];
        [_bankNameLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_bankIcon.mas_right).offset(rate375(9));
            make.top.equalTo(_bankIcon.mas_top).offset(5);
        }];
        _bankNameLbl.text = @"建设银行";
        _bankNameLbl.font = [UIFont systemFontOfSize:font12ScreenWRate *LKScreenW];
        _bankNameLbl.textColor = [UIColor whiteColor];
    }
    return _bankNameLbl;
}

-(UILabel *)bankNumLbl
{
    if (_bankNumLbl == nil) {
        _bankNumLbl = [UILabel new];
        [self.contentView addSubview:_bankNumLbl];
        [_bankNumLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_bankNameLbl.mas_left);
            make.bottom.equalTo(_bankIcon.mas_bottom).offset(1);
        }];
        _bankNumLbl.text = @"**** **** **** 9911";
        _bankNumLbl.font = [UIFont systemFontOfSize:font20ScreenWRate *LKScreenW];
        _bankNumLbl.textColor = [UIColor whiteColor];
    }
    return _bankNumLbl;
}

- (UILabel *)bankTypeLbl
{
    if (_bankTypeLbl == nil) {
        _bankTypeLbl = [UILabel new];
        [self.contentView addSubview:_bankTypeLbl];
        [_bankTypeLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_bankNameLbl.mas_top);
            make.right.equalTo(_bankNumLbl.mas_right);
        }];
        _bankTypeLbl.text = @"储蓄卡";
        _bankTypeLbl.font = [UIFont systemFontOfSize:font12ScreenWRate *LKScreenW];
        _bankTypeLbl.textColor = [UIColor whiteColor];
    }
    return _bankTypeLbl;
}
@end
